package org.example.ymcc.feignclient.fallback;

import feign.hystrix.FallbackFactory;
import org.example.ymcc.domain.CourseDoc;
import org.example.ymcc.feignclient.ESFeignClient;
import org.example.ymcc.result.JsonResult;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ESFeignClientFallbackFactory implements FallbackFactory<ESFeignClient> {
    @Override
    public ESFeignClient create(Throwable throwable) {
        return new ESFeignClient() {
            @Override
            public JsonResult batchSave(List<CourseDoc> docList) {
                return JsonResult.error(throwable.getMessage());
            }

            @Override
            public JsonResult getCourseDoc(Long courseId) {
                return JsonResult.error(throwable.getMessage());
            }
        };
    }
}
